<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>党员积分排名</title>
    <meta name="description" content="这是一个 index 页面">
    <meta name="keywords" content="index">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="icon" type="image/png" href="assets/i/favicon.png">
    <link rel="apple-touch-icon-precomposed" href="assets/i/app-icon72x72@2x.png">
    <meta name="apple-mobile-web-app-title" content="Amaze UI" />
    <link rel="stylesheet" href="assets/css/amazeui.min.css" />
    <link rel="stylesheet" href="assets/css/amazeui.datetimepicker.css" />
    <link rel="stylesheet" href="assets/css/app.css">
    <link rel="stylesheet" href="assets/css/main.css">
    <script src="assets/js/jquery.min.js"></script>
    <script charset="utf-8" src="assets/kindeditor/kindeditor-all.js"></script>
    <script charset="utf-8" src="assets/kindeditor/lang/zh-CN.js"></script>
    <script>
        let name = sessionStorage.getItem("username");
        if (name === null) {
            alert("您还未登录，请登录！");
            window.location.href = "login.html";
        }
    </script>
    <style>
        #title1{
            font-size: 18px;
        }
        #title2{
            font-size: 22px;
            text-align: center;
            color: red;
        }
    </style>
</head>
<body data-type="index">
    <script src="assets/js/theme.js"></script>
    <div class="am-g tpl-g">
        <!-- 头部 -->
<div id="personSettings"></div>
<header class="main_header">

    <!-- 右侧内容 -->
    <div class="tpl-header-fluid">


        <!-- 其它功能-->
        <div class="am-fr tpl-header-navbar">
            <ul>
                <!-- 欢迎语 -->
                <li class="am-text-sm tpl-header-navbar-welcome">
                    <a href="javascript:;">欢迎你, <span id="name"></span> </a>
                </li>
                <!--个人设置-->
                <li class="am-text-sm" data-am-modal="{target: '#settings'}" onclick="settings()">
                    <a href="javascript:;">
                        <span class="am-icon-user"></span> 个人设置
                    </a>
                </li>

                <!--退出系统-->
                <li class="am-text-sm" onclick="exit()">
                    <a href="javascript:;">
                        <span class="am-icon-sign-out"></span> 退出系统
                    </a>
                </li>
            </ul>
        </div>
    </div>
</header>



        <!-- 内容区域 -->
        <div class="tpl-content-wrapper">
            <div class="am-panel am-panel-default" id="postId">
                <div class="am-panel-bd" style="display: flex;justify-content: flex-start;align-items: center">
                    <a class="flexMenu menu-bg" href="javascript:void(0)">
                        <img src="assets/img/dbxz.png">
                        <p>党员积分排名</p>
                    </a>
                    <a class="flexMenu" href="integral_ranking.html?type=2">
                        <img src="assets/img/backup.png">
                        <p>返回</p>
                    </a>
                </div>
            </div>

            <div class="row-content am-cf">

                <div class="row">

                    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                        <div class="widget am-cf">
                            <div class="widget-head am-cf">
                                <button type="button" class="am-btn am-btn-sm am-btn-success am-radius quan_xian"  rules="dy_add"  data-am-modal="{target:'#my-popup'}" onclick="clearFile()">添加信息</button>

                                <button type="button" class="am-btn am-btn-sm am-btn-danger am-radius delBtn quan_xian"  rules="dy_del">删除</button>

                                <button type="button" class="am-btn am-btn-sm am-btn-secondary am-radius quan_xian" rules="dy_output" onclick="exportDataTelement();">导出模板</button>

                                <button type="button" class="am-btn am-btn-sm  am-btn-primary am-radius quan_xian"  rules="dy_input" onchange="importData()" style="position:relative;">导入
                                    <input type="file" id="daoru" style="opacity:0;cursor: pointer;height: 37px;width: 76px; position: absolute;top: 0;left: 0">
                                </button>

                                <button type="button" class="am-btn am-btn-sm am-btn-warning   am-radius" onclick="exportData();">导出EXCEL</button>
                            </div>

                            <div class="widget-body  am-fr">
                              
                                <div class="am-u-sm-12 am-scrollable-horizontal">
                                    <table width="100%" id="table" class=" am-table-hover am-text-nowrap am-table-bordered am-table-centered am-table am-table-compact am-table-striped tpl-table-black ">
                                        <thead>
                                            <tr>
                                                <th>√</th>
                                                <th>排名</th>
                                                <th>姓名</th>
                                                <th>星级</th>
                                                <th>积分</th>
                                                <th class="cz">操作</th>
                                            </tr>
                                        </thead>
                                        <tbody id="show">
                                            <!-- more data -->
                                        </tbody>
                                    </table>
                                </div>
                                <div class="am-u-lg-12 am-cf">

                                    <!-- <div class="am-fr">
                                        <ul class="fenye fenye_zz am-pagination tpl-pagination">
                                            <li class="am-active"><a class="first" href="#">首页</a></li>
                                            <li><a href="#" class="up">上一页</a></li>
                                            <li><a href="#" class="down">下一页</a></li>
                                            <li><a class="last" href="#">末页</a></li>
                                            <li>
                                                <a href="javascript:void(0)" style="border: none;">
                                                    页次:<span class="page_c"></span>/<span class="pagenum_c"></span>页 
                                                    <span class="strip_c"></span>条/页
                                                </a>
                                            </li>
                                            <li>
                                                <a href="javascript:void(0)" style="padding: 0">
                                                    <input class="go_page_c" type="text" value="">
                                                </a>
                                            </li>
                                            <li class="go_page_search">
                                                <a href="#">
                                                    GO
                                                </a>
                                            </li>
                                        </ul>
                                    </div> -->
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!--添加新闻-->

    <div class="am-popup am-modal-active" id="my-popup" style="height: 240px;z-index: 1302; border: 1px solid rgb(204, 204, 204);">
        <div class="am-popup-inner">
            <div class="am-popup-hd">
                <h4 class="am-popup-title">信息填报</h4>
                <input type="hidden" id="getId">
                <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>
                    x
                    <!-- &times; -->
                </a>
            </div>
            <div class="am-popup-bd" style="height: 100%;background: #ecf2ff;overflow: scroll;">
                <form class="am-form-horizontal" method="post" enctype="multipart/form-data">
                    <table width="100%" style="border-spacing: 5px" border="0" id="zqmzTable">
                        <tbody class="tbody4">
                            <tr>
                                <td colspan="2">
                                    <span style="font-size: 10pt;color: maroon">状态：添加...</span>
                                </td>
                            </tr>
                            <tr>
                                <td align="right" style="font-size: 9pt;" colspan="2">
                                    <span style="background-color: #aac9f2;padding: 2px 9px"></span>=必填项 <!-- ＃=输入数字 -->
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2" style="background-color: dimgray; height: 1px;width: 100%"></td>
                            </tr>
                            <tr>
                                <td width="15" class="TN_BASIC" style="font-size: 14px;">姓名</td>
                                <td width="85">
                                    <input type="text" id="title" style="width: 50%;">
                                </td>
                            </tr>
                            <tr>
                                <td width="15" class="TN_BASIC" style="font-size: 14px;">积分</td>
                                <td width="85">
                                    <input type="text" id="t_tel" style="width: 50%;">
                                </td>
                            </tr>

                        </tbody>
                    </table>
                    <button type="button" class="btnImg60" id="add" onclick="submitMsg()">提交</button>
                    
                    <button type="button" class="btnImg60" id="rechange" onclick="rechangeMsg()">确定</button>

                    <button type="button" class="btnImg60" data-am-modal-close="">取消</button>
                </form>
            </div>
        </div>
    </div>

    <!--模态窗口提示成功-->
    <div class="am-modal am-modal-alert " tabindex="-1" id="my-alert">
        <div class="am-modal-dialog">
            <div class="am-modal-hd users"></div>
            <div class="am-modal-bd alert">

            </div>
            <div class="am-modal-footer">
                <span class="am-modal-btn">确定</span>
            </div>
        </div>
    </div>
    <!-- 确认提示 -->
    <div class="am-modal am-modal-confirm" tabindex="-1" id="my-confirm" style="z-index: 1320">
      <div class="am-modal-dialog">
        <div class="am-modal-hd"></div>
        <div class="am-modal-bd">
          确定要删除这条记录吗？
        </div>
        <div class="am-modal-footer">
          <span class="am-modal-btn" data-am-modal-cancel>取消</span>
          <span class="am-modal-btn" data-am-modal-confirm>确定</span>
        </div>
      </div>
    </div>
    <script src="assets/js/amazeui.min.js"></script>
    <script src="assets/js/amazeui.datetimepicker.min.js"></script>
    <script src="assets/js/amazeui.datatables.min.js"></script>
    <script src="assets/js/app.js"></script>
</body>
<script>
    $(function(){
        function getUrlParam(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
            var r = window.location.search.substr(1).match(reg); //匹配目标参数
            if (r != null) return unescape(r[2]);
            return null; //返回参数值
        }
        var id =getUrlParam('id');
        


let token = sessionStorage.getItem("token");
let post_id = sessionStorage.getItem("post_id");
//确定模态框
$("#my-alert").on('close.modal.amui', function () {
    window.location.reload();
});
//模态框
$("#my-popup").on('close.modal.amui', function () {
    //$("#title").val("");
    $("#out_link").val("");
    //editor.html("");
    $("#time3").attr("value","");
});
//封装提交后的提示
function prompt(data, title, modal) {
    if (data.success === true) {
        $(".users").html("" + title + "");
        $(".alert").html(data.message);
        $('#my-alert').modal({ target: '#my-alert' });
        $("#" + modal + "").modal('close');

    } else {
        $(".users").html("" + title + "");
        $(".alert").html(data.message);
        $('#my-alert').modal({ target: '#my-alert' });
        $("#" + modal + "").modal('close');
    }
}
// kindeditor
KindEditor.ready(function (K) {
    editor = K.create('#editor_id', {
        uploadJson: testurl + 'kindeditor/'

    });
});
$(function () {

    loadData(1);
    //分页
    var pageNum = 1;
    $(".first").click(function(){
     pageNum =1;
        loadData(pageNum);
        $(this).parents("li").addClass("am-active").siblings().removeClass("am-active");
    });
    $(".last").click(function(){
        pageNum = $(".pagenum_c").text().trim()
        loadData(pageNum);
        $(this).parents("li").addClass("am-active").siblings().removeClass("am-active");
    });
    $(".up").click(function(){
        pageNum=$(".page_c").text().trim()
        if(pageNum == 1){
            return false;
        } else{
            pageNum--;
            loadData(pageNum);
        }
        $(this).parents("li").addClass("am-active").siblings().removeClass("am-active");
    });
    $(".down").click(function(){
        pageNum=$(".page_c").text().trim()
        if(pageNum == pages){
            return false;
        } else{
            pageNum++;
            loadData(pageNum);
        }
        $(this).parents("li").addClass("am-active").siblings().removeClass("am-active");
    });
    $(".go_page_search").click(function(){
        var pageNum_c=$(".go_page_c").val().trim()
         if (isNaN(pageNum_c)||pageNum_c=="") {
            $(".show_desc").html("只能为数字");
            $('#my-alert').modal({target: '#my-alert'});
            $(".go_page_c").val("")
            return
        }
        loadData(pageNum_c);
        $(".go_page_c").val("")
    })

    let user_ids = [];
    let checkedLength = "";
    $(".delBtn").click(function(){
        $.each($('#show input:checkbox:checked'), function () {
          let userId = $(this).val();

            user_ids.push(userId);
        });
        checkedLength = $('#show input:checkbox:checked').length;
        if(checkedLength <= 0){
            alert("请选中至少一条！");
            return false;
        }else{
            $('#my-confirm').modal({
                onConfirm: function(options) {
                    $.ajax({
                        url: testurl + "/dangyuan/deletes",
                        type: "post",
                        headers: { "Authorization": "Bearer " + token },
                        contentType: "application/json",
                        data: JSON.stringify({
                            "ids": user_ids //id数组
                        }),
                        success:function(data){
                            prompt(data,"删除党员积分","")
                        }
                    })
                },
                // closeOnConfirm: false,
                onCancel: function() {
                }
            });
        }
    });

});

//页数
let pages = 1;
function loadData(pageNum) {
    $.ajax({
        url: testurl + "/dangyuan/list",
        type: "post",
        headers: { "Authorization": "Bearer " + token },
        contentType: "application/json",
        data: JSON.stringify({
            // "pageNum":pageNum,
            "company_id":id//1历史记录、2草稿
        }),
        success: function (data) {
            let dbmessage = data.obj;
            console.log(dbmessage)
            ssd = Math.ceil(data.pageTotal / data.pageSize);
            pages = ssd;
            str = "";
            $.each(dbmessage, function (index, values) {
                var num= index+1;
                // if (values.examine_time === undefined) {
                //     values.examine_time = "";
                // }
                
                str += " <tr class=\"gradeX\">\n" +
                    "                            <td><input name='selectAll'  class='checked' value=" + values.id + " type='checkbox'></td>\n" +
                    "                                        <td>" + values.row_num + "</td>\n" +
                    "                                        <td>" + values.name + "</td>\n" +
                    "                                        <td>" + values.xingji + "</td>\n" +
                    "                                        <td>" + values.integralre + "</td>\n" +
                    
                    "                                        <td><a class=\"quan_xian\" rules=\"dy_xiu\" style=\"cursor:pointer\" data-am-modal=\"{target:'#my-popup'}\" onclick=\"getgx("+values.id+")\">修改</a></td>\n" +
                    
                        "     </tr>";

            });
            $("#show").html(str);
            $(".pagenum_c").html(pages)
            if (pageNum>=pages) {
                pageNum=pages
            }
            $(".strip_c").html(data.pageSize)
            $(".page_c").html(pageNum)
            
            rules();
        }
    });
}


//选中所有的checkbox框
$('#checkAll[name="selectAll"]').click(function () {
    if ($(this).is(':checked')) {
        $('#show input[name="selectAll"]').each(function () {

            $(this).prop("checked", true);
        });
    } else {
        $('input[name="selectAll"]').each(function () {
            $(this).removeAttr("checked", false);
        });
    }
});


exportDataTelement=function(){
    window.open(testurl + "dangyuan/template/dangyuan") ;
}

importData=function(){
    var formdata = new FormData();
    var pic = document.getElementById("daoru").files;
    for(var j=0;j<pic.length;j++){
        formdata.append(""+j+"",pic[j]);
    }
    $.ajax({
        url: testurl + '/dangyuan/leadingin/dangyuan?company_id='+id+'',
        type:"post",
        cache: false,
        headers: { "Authorization": "Bearer " + token},
        contentType: false,
        processData: false,
        data:formdata,
        success: function (data) {
            $('#my-alert').modal({ target: '#my-alert' });
            $(".users").html("导入excel");
            $(".alert").html(data.message);
        }
    })
}


// 提交
submitMsg=function(){
    let t_lb = $("#title").val();
    let t_bz = $("#t_tel").val();

    if (isNaN(t_bz)||t_bz=="") {
        $(".users").html("积分只能为数字");
        $('#my-alert').modal({target: '#my-alert'});
        return
    }
    $.ajax({
        async: false,
        url: testurl + "/dangyuan/add",
        type: "post",
        headers: { "Authorization": "Bearer " + token },
        contentType: "application/json",
        data: JSON.stringify({
            "name":t_lb,//姓名
            "company_id":id,//单位id
            "integralre":t_bz//积分
        }),
        success: function (data) {
            prompt(data,"添加成功","my-popup")
        }
    })
}  

// 提交
rechangeMsg=function(){
    let z_id = $("#getId").val();
    let t_lb = $("#title").val();
    let t_bz = $("#t_tel").val();

    if (isNaN(t_bz)||t_bz=="") {
        $(".users").html("积分只能为数字");
        $('#my-alert').modal({target: '#my-alert'});
        return
    }
    $.ajax({
        async: false,
        url: testurl + "/dangyuan/update",
        type: "post",
        headers: { "Authorization": "Bearer " + token },
        contentType: "application/json",
        data: JSON.stringify({
            "id":z_id,
            "name":t_lb,//姓名
            "company_id":id,//单位id
            "integralre":t_bz//积分
        }),
        success: function (data) {
            prompt(data,"添加成功","my-popup")
        }
    })
} 


//修改
getgx=function(e){
    $("#getId").val(e);
    $("#add").hide();
    $("#add2").hide();
    $("#rechange").show();
    $.ajax({
        url: testurl + "/dangyuan/detail",
        type: "post",
        headers: { "Authorization": "Bearer " + token },
        contentType: "application/json",
        data: JSON.stringify({
            "id": e
        }),
        success:function(data){
            console.log(data);
            let aaa = data.obj;
            $("#title").val(aaa.name);
            $("#t_tel").val(aaa.integralre);
        }
    })
}
    //清楚文件
    clearFile=function(){
        $("#title").html("");
        $("#t_tel").html("");
        $("#getId").html("");

        $("#add").show();
        $("#rechange").hide();
    }
    //导出excel     
    exportData=function(){
        var condition=$("#input").val()
        let loactionHref = testurl+"/dangyuan/export?";
        window.open(loactionHref + "&company_id=" + id);
    };

    })
</script>
</html>